﻿package view.expball
{
    import __AS3__.vec.*;
    import flash.display.*;
    import morn.core.components.*;

    public class NumItemCon extends Object
    {
        private var _numItems:Vector.<NumItem>;
        private var _numsp:View;
        private var _con:Sprite;
        private var _totalCount:int;
        private var _curCount:int;
        private var _overfunction:Function;
        private var _hBob:int;
        private var _SStr:String = "";
        public var parentW:int = 623;
        public var numUrl:String = "png.common.pow2_";

        public function NumItemCon(param1:Sprite, param2:Function, param3:int = 20)
        {
            this._con = param1;
            this._overfunction = param2;
            this._hBob = param3;
            this._numItems = new Vector.<NumItem>;
            this._numsp = new View();
            this._con.addChild(this._numsp);
            return;
        }// end function

        public function playNum(param1) : void
        {
            this._curCount = 0;
            this._SStr = param1.toString();
            this._totalCount = this._SStr.length;
            while (this._totalCount < this._numsp.numChildren)
            {
                
                this._numsp.removeChildAt(0);
            }
            this._con.x = (this.parentW - this._hBob * this._totalCount) / 2;
            this.playsingleNum();
            return;
        }// end function

        private function playsingleNum() : void
        {
            var _loc_1:NumItem = null;
            if (this._curCount < this._totalCount)
            {
                if (this._numItems.length <= this._curCount)
                {
                    _loc_1 = new NumItem(this.onComplate, this.numUrl);
                    this._numItems.push(_loc_1);
                }
                else
                {
                    _loc_1 = this._numItems[this._curCount];
                }
                _loc_1.x = (this._totalCount - this._curCount - 1) * this._hBob;
                _loc_1.setNum(int(this._SStr.charAt(this._totalCount - this._curCount - 1)));
                this._numsp.addChild(_loc_1);
            }
            else if (this._overfunction != null)
            {
                this._overfunction();
            }
            return;
        }// end function

        private function onComplate() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this._curCount + 1;
            _loc_1._curCount = _loc_2;
            this.playsingleNum();
            return;
        }// end function

        public function clear() : void
        {
            this._curCount = 0;
            this._numsp.removeAllChild();
            return;
        }// end function

        public function despose() : void
        {
            var _loc_1:int = 0;
            while (_loc_1 < this._numItems.length)
            {
                
                this._numItems[_loc_1].destory();
                this._numItems[_loc_1] = null;
                _loc_1++;
            }
            this._numItems.length = 0;
            this._numItems = null;
            this._overfunction = null;
            this._numsp.removeAllChild();
            if (this._numsp)
            {
                if (this._numsp.parent)
                {
                    this._numsp.parent.removeChild(this._numsp);
                }
                this._numsp = null;
            }
            return;
        }// end function

    }
}
